import { AudioManager1 } from "../manager/AudioManager1";
import { AdBase } from "./AdBase";

const { ccclass, property } = cc._decorator;

/** 233 游戏平台 管理类 */
@ccclass
export default class AdManager_233 extends AdBase {
    static get ins() {
        return super.getInstance<AdManager_233>();
    }

    /** 全屏视频广告ID */
    screenVieoTimer: number = null;
    /** 是否可播放全屏视频 */
    isPlaySceen: boolean = false;
    /** 全屏视频 间隔秒数 */
    screenTime: number = 60;


    /** 加载或者初始化所有广告 */
    loadAllAd() {
        this.aginScreenTime();
    };
    /** 显示Banner广告 */
    public showBanner() {
        console.log("暂不接入Banner");
    };
    /** 隐藏Banner广告 */
    public hideBanner() {
        console.log("暂不接入Banner");
    };
    /** 播放插屏广告 */
    public showIntersAd() {
        console.log("暂不接入插屏广告");
        //     jsb.reflection.callStaticMethod("org/cocos2dx/javascript/AdManage", "showInterstitialAd", "()V");
    }
    /** 播放视频广告  成功回调   失败回调 */
    public showVideoAd(finishBack?: Function, errorBack?: Function, countNum?: number) {
        if (finishBack) {
            this.videoBack = finishBack;
        } if (errorBack) {
            this.errorBack = errorBack;
        }

        console.log("播放视频广告_233");
        jsb.reflection.callStaticMethod("org/cocos2dx/javascript/AdManage", "showRewardedVideoAd", "()V");
    }
    /** 播放全屏广告 */
    public showScreenVideoAd() {
        if (!this.isPlaySceen) { return; }
        console.log("播放全屏广告_233");
        jsb.reflection.callStaticMethod("org/cocos2dx/javascript/AdManage", "showScreenVideoAd", "()V");
        this.isPlaySceen = false;
        this.aginScreenTime();
    }
    /** 视频播放完成 */
    finishVideo() {
        AudioManager1.resumeMusic();
        if (this.videoBack) {
            this.videoBack();
        }
        this.videoBack = null;
        this.errorBack = null;
    }
    /** 视频播放失败 isOut 是否中途退出*/
    errorVideo() {
        AudioManager1.resumeMusic();
        if (this.errorBack) {
            this.errorBack();
        }
        this.videoBack = null;
        this.errorBack = null;
    };


    /** 重置全屏视频时间 */
    aginScreenTime() {
        if (this.screenVieoTimer) {
            clearTimeout(this.screenVieoTimer);
            this.isPlaySceen = false;
        }
        this.screenVieoTimer = setTimeout(() => {
            this.isPlaySceen = true;
            this.screenVieoTimer = null;
        }, this.screenTime * 1000);
    };
}
